package com.qian.saas.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qian.saas.domain.Dev;
import com.qian.saas.domain.Rep;
import com.qian.saas.domain.Users;
import com.qian.saas.domain.Vo.RepVo;
import com.qian.saas.mapper.DevMapper;
import com.qian.saas.mapper.RepMapper;
import com.qian.saas.mapper.UsersMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 微信端接口
 */
@RestController
@RequestMapping("/wx")
@CrossOrigin

public class WxController {

    @Resource
    private RepMapper repMapper;

    @Resource
    private UsersMapper usersMapper;

    @Resource
    private DevMapper devMapper;

    @PostMapping("/bx")
    public R tj(@RequestBody Rep rep){
        System.out.println(rep);
        rep.setCreatetime(LocalDateTime.now());
        rep.setSt(1);
        rep.setUptime(LocalDateTime.now());
        repMapper.insert(rep);
        return R.success("成功");
    }

    @GetMapping("/sel")
    public R sel(){
        QueryWrapper wrapper=new QueryWrapper<>();
        wrapper.eq("type","技术");
        List<Users> list = usersMapper.selectList(wrapper);
        List<Dev> devs = devMapper.selectList(null);
        System.out.println(list);
        System.out.println(devs);
        Map inf=new HashMap();
        inf.put("dev",devs);
        inf.put("use",list);
        return R.success(inf);
    }

    @GetMapping("/selrep")
    public R selrep(){
        List<Rep> records = repMapper.selectList(null);

        List repVos=new ArrayList();
        for (Rep record : records) {
            RepVo repVo=new RepVo();
            if(record.getDevid()!=null){
                QueryWrapper wrapper=new QueryWrapper();
                wrapper.eq("devid",record.getDevid());
                Dev dev = devMapper.selectOne(wrapper);
                repVo.setDevname(dev.getDevname());
            }
            repVo.setDevid(record.getDevid());
            repVo.setRepid(record.getRepid());
            repVo.setCreatetime(record.getCreatetime());
            repVo.setUptime(record.getUptime());
            repVo.setQu(record.getQu());
            repVo.setJlqu(record.getJlqu());
            repVo.setSt(record.getSt());
            repVos.add(repVo);
        }

        return R.success(repVos);
    }

}
